unit UMain_Frm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes
, FMX.Forms
// , System.Variants
// FMX.Types, FMX.Controls, FMX.Forms, FMX.StdCtrls,
// FMX.Layouts, FMX.Objects, FMX.ImgList,
// FMX.Controls.Presentation
, FMX.
Platform
// , FMX.ScrollBox
, FMX.Memo
, System.Messaging, FMX.Types, FMX.Controls, FMX.Controls.Presentation,
FMX.ScrollBox
;
type
TMain_Frm =
class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FOrientationChangedId: Integer;
{ Private declarations }
procedure EvOnOrientationChanged(
const Sender: TObject;
const Msg: TMessage);
function EvOnAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
procedure Log(
const ALog :
String);
public
{ Public declarations }
end;
var
Main_Frm: TMain_Frm;
implementation
{$R *.fmx}
procedure TMain_Frm.FormCreate(Sender: TObject);
var
aFMXApplicationEventService: IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService))
then
aFMXApplicationEventService.SetApplicationEventHandler(EvOnAppEvent)
else
Log('
Application Event Service is not supported.');
//Subscribe to orientation change events in OnCreate or similar
FOrientationChangedId := TMessageManager.DefaultManager.SubscribeToMessage(
TOrientationChangedMessage, EvOnOrientationChanged);
end;
procedure TMain_Frm.FormDestroy(Sender: TObject);
begin
//Unsubscribe from orientation change events in OnDestroy or similar
TMessageManager.DefaultManager.Unsubscribe(TOrientationChangedMessage, FOrientationChangedId);
end;
procedure TMain_Frm.Log(
const ALog:
String);
begin
Memo1.Lines.Insert(0, ALog);
end;
procedure TMain_Frm.EvOnOrientationChanged(
const Sender: TObject;
const Msg: TMessage);
begin
Log('
Orientation changed: ' + Msg.ToString);
end;
function TMain_Frm.EvOnAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
case AAppEvent
of
TApplicationEvent.FinishedLaunching: Log('
Finished Launching');
TApplicationEvent.BecameActive: Log('
Became Active');
TApplicationEvent.WillBecomeInactive: Log('
Will Become Inactive');
TApplicationEvent.EnteredBackground: Log('
Entered Background');
TApplicationEvent.WillBecomeForeground: Log('
Will Become Foreground');
TApplicationEvent.WillTerminate: Log('
Will Terminate');
TApplicationEvent.LowMemory: Log('
AppEvent: Low Memory');
TApplicationEvent.TimeChange: Log('
AppEvent: Time Change');
TApplicationEvent.OpenURL: Log('
AppEvent: Open URL');
else
Log('
AppEvent: Unknown');
end;
Result := True;
end;
end.